/*
 *==============================================================================
    THIS SOURCE CODE IS PROPRIETARY INFORMATION BELONGING TO SKYMOBI, INC.
	ANY USE INCLUDING BUT NOT LIMITED TO COPYING OF CODE, CONCEPTS, AND/OR
	ALGORITHMS IS PROHIBITED EXCEPT WITH EXPRESS WRITTEN PERMISSION BY THE 
	COMPANY.

	THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
	KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
	IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
	PURPOSE.

	Copyright (c) 2005 - 2010  SKYMOBI Corporation.  All Rights Reserved.
 *==============================================================================
 */

/*
	*****************************************************************************
	*
	*    
	*   This code was based on the GSM AMR-NB speech codec R98
	*   Created by celery on 2010-4-7                           
	*
	*****************************************************************************
	*
	*      File             : sk_amr_nb_coder.h
	*      Purpose          : Declaration of sk_amr_nb_coder
	*
	*****************************************************************************
*/

#ifndef _SK_AMR_NB_CODER_H_
#define _SK_AMR_NB_CODER_H_

#ifdef _cplusplus
extern "C" {
#endif

#define AMR_MAGIC_NUMBER "#!AMR\n"
#define L_FRAME      160   
#define MAX_SERIAL_SIZE 244    /* max. num. of serial bits                 */
#define MAX_PACKED_SIZE (MAX_SERIAL_SIZE / 8 + 2)

typedef  void* SK_AMR_NB_Coder_Handle;

typedef enum
{
	AMRNB_OK = 0,		 // OK
	AMRNB_ERR_ALLOC,		 // memory allocation error
	AMRNB_ERR_BITS,		 // parsing bit-stream error
	AMRNB_ERR_PARA,		 // invalid parameter value
	AMRNB_ERR_NOTSUPPORT, // can not support
	AMRNB_ERR_UNKNOW,     //  unknown error
}SK_AMRNB_Ret;

/************************************************************************/
/*
	API function: SK_AMRNBCoder_Init
	Description:  Initializing the AMR NB Coder
	Parameters Description:
	Input:
	argument 1: the handle of AMRNB Coder
	argument 2: the bit rate selection, it's between 0 and 8
	argument 3: whether using the dtx or not, it's better set 1.
*/
/************************************************************************/

SK_AMRNB_Ret  SK_AMRNBCoder_Init(SK_AMR_NB_Coder_Handle* AMR_Coder_Handle, int mode, int allow_dtx);


/************************************************************************/
/*
	API function: SK_AMRNBCoder_Switch_Mode
	Description:  Switching the bit rate when the coder is working for every frame.
	Parameters Description:
	Input:
	argument 1: the handle of AMRNB Coder
	argument 2: the bit rate selection, it's between 0 and 8
*/
/************************************************************************/

SK_AMRNB_Ret  SK_AMRNBCoder_Switch_Mode(SK_AMR_NB_Coder_Handle AMR_Coder_Handle, int code_mode);


/************************************************************************/
/*
	API function: SK_AMRNBCoder_Enc
	Description:  Converting the 8k and 16bits PCM data into AMR NB bits-stream
	Parameters Description:
	Input:
	argument 1: the PCM data buffer
	argument 2: the PCM data buffer size, it must set 160
	argument 4: the handle of AMRNB Coder
	output:
	argument 2: the bit number of packet
	argument 3: AMR NB bits-stream buffer
*/
/************************************************************************/

SK_AMRNB_Ret  SK_AMRNBCoder_Enc(signed short* pcmBuffer, int* buffer_size, unsigned char* packed_bits, SK_AMR_NB_Coder_Handle AMR_Coder_Handle);


/************************************************************************/
/*
	API function: SK_AMRNBCoder_Close
	Description:  Releasing the memory for the AMR NB Coder
	Parameters Description:
	Input:
	argument 1: the handle of AMRNB Coder
*/
/************************************************************************/

SK_AMRNB_Ret  SK_AMRNBCoder_Close(SK_AMR_NB_Coder_Handle AMR_Coder_Handle);

#ifdef _cplusplus
}
#endif

#endif
